<?php
use \PsiFramework\Classes\Util\UI\Printer;
use \PsiFramework\Classes\Util\UI\HTML;
use \PsiFramework\Classes\Util\Log\Logger;

$discount = $response->getAttribute("object");
$objectType = $response->getAttribute("objectType");
?>
<form
    class="editForm"
    method="POST"
    action="<?php Printer::display(HTML::linkHref('action=CMS.Save&type='.$objectType));?>">
    <?php
    if ($discount != null) {
    ?>
    <input
        type="hidden"
        name="id"
        value="<?php Printer::display($discount->getId()); ?>" />
    <?php
    }
    ?>
    <div class="label">
        <span class="titre">Code :</span>
        <input
            class="firstInput"
            type="text"
            name="code"
            value="<?php if ($discount != null) Printer::display($discount->getCode()); ?>" />
    </div>
    <div class="label" id="category">
        <span class="titre">Catégorie :</span>
        <input
            class="firstInput fieldTypeSelecter"
            type="text"
            id="category_name"
            name="category_name"
            value="<?php
                if ($discount != null && $discount->getCategory()!=null) {
                    Printer::display($discount->getCategory()->getName());
                } 
            ?>" />
        <input
            class="firstInput inputId"
            type="hidden"
            id="category_id"
            name="category_id"
            value="<?php
                if ($discount != null && $discount->getCategory()!=null) {
                    Printer::display($discount->getCategory()->getId());
                }
            ?>" />
    </div>
    <div class="label">
        <span class="titre">Quantité min :</span>
        <input
            class="firstInput"
            type="text"
            name="min_quantity"
            size="1"
            value="<?php if ($discount != null) Printer::display($discount->getMinQuantity()); ?>" />
    </div>
    <div class="label">
        <span class="titre">Quantité max :</span>
        <input
            class="firstInput"
            type="text"
            name="max_quantity"
            size="1"
            value="<?php if ($discount != null) Printer::display($discount->getMaxQuantity()); ?>" />
    </div>
    <div class="label">
        <span class="titre">Valeur :</span>
        <input
            class="firstInput"
            type="text"
            name="value"
            size="1"
            value="<?php if ($discount != null) Printer::display($discount->getValue()); ?>" />
    </div>
    <div class="label">
        <span class="titre">Valeur en pourcentage :</span>
        <input
            class="firstInput"
            type="radio"
            name="percentage"
            value="1"
            <?php if ($discount == null || ($discount != null && $discount->isPercentage())) echo 'checked="checked"'; ?>
            />Oui
        <input
            class="firstInput"
            type="radio"
            name="percentage"
            value="0" 
            <?php if (($discount != null && !$discount->isPercentage())) echo 'checked="checked"'; ?>
            />Non
    </div>
    <input type="submit" value="OK" />
</form>
<script type="text/javascript">
    $(document).ready(function() {

        $("#category_name").autocomplete({
            source: "?service=ListItemCategories&format=json",
            select: function(event, ui) {
                $("#category_name").val(ui.item.label);
                $("#category_id").val(ui.item.id);
            }
        });
    });
</script>
